package com.tgy.JUC.Single;

/***
 * @ClassName: LazyMan
 * @Description: 懒汉式单例模式, 多线程不安全
 * @Auther: 送你一块二向箔
 * @Date: 17:10 2022/3/15
 * @version : V1.0
 */
public class LazyMan {
    private static LazyMan lazyMan;

    //构造器私有
    private LazyMan() {
        System.out.println(Thread.currentThread().getName());
    }

    public static LazyMan getInstance() {
        if (lazyMan == null) {
            lazyMan = new LazyMan();
        }
        return lazyMan;
    }

    // 多线程并发创建对象存在问题。
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                LazyMan.getInstance();
            }).start();
        }
    }
}
